import type { BasePageReq } from '@wlydfe/service'
import type { RoleModel, UserModel } from './type'
import http from '@/service'
/**
 * 用户管理-用户列表
 *
 * @param data 搜索参数
 */
export const getUserPage = (data: BasePageReq<Partial<UserModel>>) => {
  return http.post<UserModel[]>(
    {
      url: '/user/page',
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 用户管理-停用用户
 *
 * @param id 用户ID
 */
export const suspensionUserInfo = (id: string) => {
  return http.post(
    {
      url: `/user/account/suspension/${id}`,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 用户管理-停用用户
 *
 * @param id 用户ID
 */
export const activationUserInfo = (id: string) => {
  return http.post(
    {
      url: `/user/account/activation/${id}`,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 用户管理-删除用户
 *
 * @param id 用户ID
 */
export const deleteUser = (id: string) => {
  return http.post(
    {
      url: `/user/accountDel/${id}`,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 用户管理-查询用户详情
 *
 * @param id 用户ID
 */
export const getUserInfoById = (id: string) => {
  return http.post(
    {
      url: `/user/info/${id}`,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 用户管理-用户编辑
 *
 * @param isAdd 是否新增
 * @param data
 */
export const addOrEditUser = (isAdd: boolean, data: Partial<UserModel>) => {
  const url = isAdd ? '/user/add' : '/user/update'
  return http.post(
    {
      url,
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 管理端权限-角色列表
 *
 * @param data 搜索参数
 */
export const getRolePage = (data: BasePageReq<Partial<RoleModel>>) => {
  return http.post(
    {
      url: '/role/platform/page',
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 角色管理-角色编辑
 *
 * @param isAdd 是否新增
 * @param data
 */
export const addOrEditRole = (isAdd: boolean, data: Partial<RoleModel>) => {
  const url = isAdd ? '/role/create' : `/role/${data.roleId}/update`
  return http.post(
    {
      url,
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 角色管理-删除角色
 *
 * @param id 用户ID
 * @param data
 */
export const deleteRole = (id: string, data: Record<string, any>) => {
  return http.post(
    {
      url: `/role/${id}/delete`,
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 角色管理-查询角色已分配菜单
 *
 * @param roleId
 */
export const queryRoleAssignedList = (roleId: string) => {
  return http.post(
    {
      url: `/resource/platform/31/${roleId}`,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}

/**
 * 角色菜单权限重新分配
 *
 * @param roleId
 * @param data
 */
export const assignUserPermission = (roleId, data = {}) => {
  return http.post(
    {
      url: `/role/${roleId}/resources/update`,
      data,
    },
    { urlGateway: '/gtsp-orch-platform' },
  )
}
